function Jumppages(selector) {
	this.ele = $(selector).get(0);
	$(this.ele).find('li').on({
		'click': function() {
			this.index = $(this).index();
			if(this.index == 3) {
				window.open("landingpage.html");
			} else if(this.index == 2) {
				window.open("registerpage.html");
			}
		}
	})

}
//购物车
function Addpro(selector) {
	this.ele = $(selector).get(0);
	this.action();
	this.skip();
}

Addpro.prototype.action = function() {
	var _this = this;
	this.totalPrice = 0;
	var $tr1 = '<ul><li><img src="" alt="" class="newimg"/></li><li><span class="textone"></span><span class="texttwo"></span></li ><li class="numbtn"><i id="left">-</i><span class="num1">1</span><i id="right">+</i></li><li class="highprice"></li><li class="price"></li><li class="main_delect">删除</li></ul>'
	if(getCookie('shoplist')) {
		$(this.ele).find('.main_banner').css('display', 'none');
		$(this.ele).find('.main_inner').css('display', 'block');
		var arr = JSON.parse(getCookie('shoplist'));
		for(var i = 0; i < arr.length; i++) {
			$(this.ele).find('.main_inforcount').append($tr1);
			$('.main_inforcount').find('.newimg').eq(i).attr('src', arr[i].img);
			$('.main_inforcount').find('.textone').eq(i).html('礼品名称：' + arr[i].name);
			$('.main_inforcount').find('.texttwo').eq(i).html(arr[i].have);
			$('.main_inforcount').find('.highprice').eq(i).html(arr[i].highprice);
			$('.main_inforcount').find('.price').html('￥' + arr[i].price);
			$('.main_inforcount').find('.num1').eq(i).html(arr[i].count);
			_this.totalPrice += parseInt(arr[i].price) * $(this.ele).find('.num1').html();
			$(_this.ele).find('.allcount').html('￥' + _this.totalPrice);
		}
		
	} else{
		$(this.ele).find('.empty').css('display', 'block');
		$(this.ele).find('.have').css('display', 'none');
	}

	$(this.ele).find('.main_delect').click(function() {
		_this.totalPrice=0
		this.index = $(this).parents('ul').index();
		$('.main_inforcount').find('ul').eq(this.index).remove();
		arr.splice(this.index, 1);
		setCookie('shoplist', JSON.stringify(arr), {
			expires: 7,
			path: '/'
		});
		for(var j = 0; j < arr.length; j++) {
			_this.totalPrice+= parseInt(arr[j].price) * arr[j].count;
			$(_this.ele).find('.allcount').html('￥' + _this.totalPrice)
		}
		
		if(!JSON.parse(getCookie('shoplist')).length) {
			$(_this.ele).find('.main_banner').css('display', 'block');
			$(_this.ele).find('.main_inner').css('display', 'none');
		}
	})

		$(_this.ele).find('.numbtn i').click(function() {
			_this.totalPrice=0
			this.index = $(this).parents('ul').index();
			console.log(this.index)
			if(this.id == 'right') {
				arr[this.index].count++

			} else if(this.id == 'left') {
				if(arr[this.index].count> 1) {
					arr[this.index].count--;
				}
			}
			setCookie('shoplist', JSON.stringify(arr), {
				expires: 7,
				path: '/'
			});
			console.log(arr[this.index].count)
			for(var k = 0; k < arr.length; k++) {
				$('.num1').eq(k).html(arr[k].count)
				_this.totalPrice += parseInt(arr[k].price) * arr[k].count;
				$(_this.ele).find('.allcount').html('￥' + _this.totalPrice)
			}
		})
		
}
Addpro.prototype.skip=function(){
	var _this = this;
	$(this.ele).find('.textone').click(function(){
		window.open("detailspage.html");
	})
	$(this.ele).find('.goindex,.goindex2').click(function(){
		window.open("index.html");
	})

}
